{extend name="public:layout" /}

{block name="title"}
  <title>{:site('siteName')}-友豆账号</title>
{/block}

{block name="css"}
    <style>
        .layui-btn{    height: 25px;line-height: 25px;    padding: 0 3px;}
        .layui-form-item .layui-input-inline{    margin: 0 0 10px 0px;}
    </style>
{/block}

{block name="content"}
    <div class="head">友豆账号</div>
    <div class="layui-form-item" style="margin-top:6px;">
        <form class="layui-form" action="">
            <div class="layui-input-inline">
                <select name="onekey" lay-filter="onekey">
                    <option value="0">一键收豆助手</option>
                    <option value="1">收推荐奖为{:config("currency")["money"]}</option>
                    <option value="2">收推荐奖为{:config("currency")["recharge"]}</option>
                    <option value="3">收分红奖为{:config("currency")["money"]}</option>
                    <option value="4">收分红奖为{:config("currency")["recharge"]}</option>
                </select>
            </div>
        </form>
    </div>
    <div class="account_li">
        <ul>
            {volist name="accounts" id="v"}
                <li>
                    <p><span>账户名</span><br />{$v.name}</p>
                    <p><span>推荐奖</span><br />{$v.invite}</p>
                    <p><span>每日分红</span><br />{$v.money}</p>
                    <p><span>累计分红</span><br />{$v.total}</p>
                    <p><span>剩余分红</span><br />{$v.balance}</p>
                    <p><span>激活时间</span><br />{$v['time'] ? date('Y-m-d',$v['time']) : '暂无'}</p>
                    <p>
                        <span>状态</span><br />
                        {eq name="v.status" value="0"}未激活{/eq}
                        {eq name="v.status" value="1"}分红中{/eq}
                        {eq name="v.status" value="2"}已出局{/eq}
                    </p>
                    <p><span>操作</span><br />
                        {eq name="v.status" value="0"}
                            <button class="layui-btn layui-btn-mini layui-btn-main confirm_pwd active_confirm" aid="{$v.id}">激活</button>
                        {/eq}
                        {gt name="v.status" value="0"}
                            <button class="layui-btn layui-btn-mini layui-btn-red get_money" main_id="{$v.id}">收{:config("currency")["money"]}</button>
                            <button class="layui-btn layui-btn-mini layui-btn-warm get_recharge" main_id="{$v.id}">收{:config("currency")["recharge"]}</button>
                        {/gt}   
                    </p>
                </li>
            {/volist}
        </ul>
    </div>
{/block}

{block name="script"}
    <script type="text/javascript">
        layui.use(['form', 'layer'], function(){
            var $ = layui.jquery;
            var layer = layui.layer;
            var form = layui.form();
            //激活
            $(".active_confirm").click(function() {
                var aid = $(this).attr('aid');
                var msg = '激活此账户需要'+ '{:config("abonus")["main_price"]}' +'个'+ '{:config("currency")["recharge"]}' +'，确定？';
                checkPwd(function(pwd){
                    layer.confirm(msg, {
                        btn: ['激活', '取消'],
                        icon: 3
                    }, function(index) {
                        layer.close(index);
                        $.post('{:url("index/account/index")}', {id: aid,pwd:pwd}, function(res) {
                            if(res.status == 1){
                                layer.msg(res.msg, {
                                    time: 1000
                                }, function() {
                                    location.reload();
                                });
                            }else{
                                layer.msg(res.msg);
                            }
                        });
                    });
                });
                return false;
            });

            //收分红币
            $('.get_money').click(function(){
                var main_id = $(this).attr('main_id');
                var full_money = '{:config("abonus")["full_money"]}';
                checkPwd(function(pwd){
                    layer.prompt({
                        title: '请输入要收的数量，不能低于'+full_money+'个',
                    }, function(num, index, elem){
                        if(!/^\+?[1-9][0-9]*$/.test(num)){
                            layer.msg('请输入一个正整数');
                            return;
                        }
                        if(num < full_money){
                            layer.msg('数量不能低于'+full_money+'个');
                            return;
                        }
                        $.post("{:url('index/account/getMoney')}", {id: main_id,num:num,pwd:pwd,type:1}, function(res) {
                            if(res.success == 1){
                                layer.close(index);
                                layer.msg(res.msg, {time: 1000}, function() {
                                    location.reload();
                                });
                            }else{
                                layer.msg(res.msg);
                            }
                        },'json');
                    });
                });
                return false;
            });

            //收充值币
            $('.get_recharge').click(function(){
                var main_id = $(this).attr('main_id');
                var full_recharge = '{:config("abonus")["full_recharge"]}';
                checkPwd(function(pwd){
                    layer.prompt({
                        title: '请输入要收的数量，不能低于'+full_recharge+'个',
                    }, function(num, index, elem){
                        if(!/^\+?[1-9][0-9]*$/.test(num)){
                            layer.msg('请输入一个正整数');
                            return;
                        }
                        if(num < full_recharge){
                            layer.msg('数量不能低于'+full_recharge+'个');
                            return;
                        }
                        $.post("{:url('index/account/getRecharge')}", {id: main_id,num:num,pwd:pwd,type:1}, function(res) {
                            if(res.success == 1){
                                layer.close(index);
                                layer.msg(res.msg, {time: 1000}, function() {
                                    location.reload();
                                });
                            }else{
                                layer.msg(res.msg);
                            }
                        },'json');
                    });
                });
                return false;
            });
            //一键收豆
            form.on('select(onekey)', function(data){
                if(data.value > 0){
                    checkPwd(function(pwd){
                        $.post("{:url('index/account/onekey')}", {type: data.value,pwd:pwd,diff:1}, function(res) {
                            if(res.success == 1){
                                layer.msg(res.msg, {time: 1000}, function() {
                                    location.reload();
                                });
                            }else{
                                layer.msg(res.msg);
                            }
                        },'json');
                    });
                }
                return false;
            });
        });
    </script>
{/block}